<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<% 
	String xm_id = request.getParameter("xm_id") == null ? "" : request.getParameter("xm_id");
	String xm_code = request.getParameter("xm_code") == null ? "" : request.getParameter("xm_code");
	String xm_name = request.getParameter("xm_name") == null ? "" : request.getParameter("xm_name");
	String invoice_title = request.getParameter("invoice_title") == null ? "" : request.getParameter("invoice_title");
	String invoice_id = request.getParameter("invoice_id") == null ? "" : request.getParameter("invoice_id");
	String account_receivable=request.getParameter("account_receivable") == null ? "0" : request.getParameter("account_receivable");
	String has_receivable=request.getParameter("has_receivable") == null ? "0" : request.getParameter("has_receivable");
	String warranty_value=request.getParameter("warranty_value") == null ? "0" : request.getParameter("warranty_value");
	String end_finish=request.getParameter("end_finish") == null ? "0" : request.getParameter("end_finish");
%>
<html>
	<head>
		<title>项目收款管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#table").datagrid({
				title:"项目结算收款管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMInMoney?invoice_id=<%=invoice_id%>&in_type=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'创建时间',field:'operation_time',width:150,align:'center'},
					{title:'部门',field:'dept_name',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:100,align:'center'},
					{title:'票据抬头',field:'invoice_title',width:150,align:'center'},
					//{title:'开票人',field:'creator',width:100,align:'center'},
					{title:'开票额',field:'account_receivable',width:100,align:'center'},
					//{title:'已收额',field:'has_receivable',width:100,align:'center'},
					{title:'本次回款额',field:'in_money',width:100,align:'center'},
					{title:'管理费',field:'manage_money',width:100,align:'center'},
					//{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteData('"+rowData.id+"');\"/>";
							return str;
						}
						if(rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> ";
							return str;
						}
						if(rowData.status == 1 || rowData.status == 3){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_INMONEY_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewData('"+rowData.id+"');\"/>";
	                    	return str;
						}
	                    return str;
					}}
				]],
				toolbar:[{
					iconCls: 'icon-add',
					text:'新增结算收款',
					handler:function(){
						addInMoney();
					}
				}],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
        function addInMoney(){
        	var param = "callback=rtCallBack&xm_id=<%=xm_id%>&xm_code="+encodeURIComponent('<%=xm_code%>')+"&xm_name="+encodeURIComponent('<%=xm_name%>')+"&invoice_title="+encodeURIComponent('<%=invoice_title%>')+"&invoiceId=<%=invoice_id%>&account_receivable=<%=account_receivable%>&has_receivable=<%=has_receivable%>&warranty_value=<%=warranty_value%>";
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInMoneyEnd.jsp?"+param,1000, 800);
        }
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditInMoneyEnd.jsp?isShow=1&id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_INMONEY_SHENPI%>")+"&businessId="+id+"&isShow=1";
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteInMoney",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function  editXMInvoice(id){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInMoneyEnd.jsp?invoice_type=1&id="+id+"&callback=rtCallBack&isShow=0",1000, 800);
	
		}
		function  viewData(id){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInMoneyEnd.jsp?invoice_type=1&id="+id+"&isShow=1",1000, 800);
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}

	</script>
		<body>
		<div id="table" data-options="fit:true" ></div>
	</body>
</html>
